package org.dromara.system.service.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;
import org.dromara.system.mapper.SysOssMapper;
import org.dromara.system.pojo.bo.SysOssBO;
import org.dromara.system.pojo.entity.SysOssDO;
import org.dromara.system.pojo.qo.SysOssQO;
import org.dromara.system.pojo.vo.SysOssVO;
import org.dromara.system.service.SysOssService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * OSS对象存储表 服务层实现。
 *
 * @author mkj
 * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysOssServiceImpl implements SysOssService {

    private final SysOssMapper sysOssMapper;

    @Override
    public boolean add(SysOssBO sysOssBO) {
        SysOssDO sysOssDO = BeanCopyUtils.copy(sysOssBO, SysOssDO.class);
        return sysOssMapper.insert(sysOssDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysOssMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysOssBO sysOssBO) {
        SysOssDO sysOssDO = BeanCopyUtils.copy(sysOssBO, SysOssDO.class);
        return sysOssMapper.update(sysOssDO) > 0;
    }

    @Override
    public List<SysOssVO> list(SysOssQO sysOssQO) {
        SysOssDO sysOssDO = BeanCopyUtils.copy(sysOssQO, SysOssDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysOssDO);
        return sysOssMapper.selectListByQueryAs(queryWrapper, SysOssVO.class);
    }

    @Override
    public SysOssVO getInfo(Long id) {
        SysOssDO sysOssDO = sysOssMapper.selectOneById(id);
        if (sysOssDO == null) {
            return null;
        }
        return BeanCopyUtils.copy(sysOssDO, SysOssVO.class);
    }

    @Override
    public Page<SysOssVO> page(SysOssQO page) {
        return sysOssMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysOssVO.class);
    }

}

